package com.ld.security.auth.server.modules.sys.service.impl;

import com.ld.security.auth.server.modules.sys.entity.SysUser;
import com.ld.security.auth.server.modules.sys.service.ISysUserService;
import com.ld.security.common.mybatis.constant.SqlCondition;
import com.ld.security.common.core.util.UuidUtil;
import com.ld.security.common.mybatis.base.service.*;
import com.ld.security.common.mybatis.core.wrapper.EntityWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
 class  SysUserServiceImpl extends ISuperServiceImpl<SysUser> implements
        ISysUserService {


    /**
     * 根据用户名查询函数封装，会是产生预编译sql
     * Select * from sys_user where username = ?
     * @param username
     * @return
     */
    @Override
    public SysUser findByUsername(String username) {
        EntityWrapper ew =  this.getWrapper();
        ew.addField("username",SqlCondition.eq,username);
        return superMapping.selectOne(ew);
    }

    @Override
    public int save(SysUser entity) {
        SysUser sysUser =  this.getById(entity.getId());
        if(sysUser != null){
            if(entity.getPassword().equals(sysUser.getPassword())){
                //密码相同取消加密
                entity.setPassword(null);
            }
        }

        return super.save(entity);
    }
}
